package com.devin.dao;

import com.devin.pojo.Product;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;
import java.util.List;

public interface ProductMapper {

    @Select(" select * from product ")
    List<Product> findAllProducts();

    @Insert(" insert into product values(null,replace(uuid(),'-',''),#{productName,jdbcType=VARCHAR},#{cityName,jdbcType=VARCHAR},#{departureTime,jdbcType=DATE},#{productPrice,jdbcType=DOUBLE},#{productDesc,jdbcType=VARCHAR},#{productStatus,jdbcType=INTEGER})")
    void addProduct(Product product);

    @Delete(" delete from product where id=#{id}")
    void delProduct(Integer id);

    @Select(" select * from product where id=#{productId}")
    @Results({@Result(id = true,property = "id",column = "id"),
            @Result(property = "productNum",column = "productNum",/*javaType = String.class,*/jdbcType = JdbcType.VARCHAR),
            @Result(property = "productName",column = "productName",/*javaType = String.class,*/jdbcType = JdbcType.VARCHAR),
            @Result(property = "cityName",column = "cityName"/*,javaType = String.class*/,jdbcType = JdbcType.VARCHAR),
            @Result(property = "departureTime",column = "DepartureTime"/*,javaType = String.class*/,jdbcType = JdbcType.DATE),
            @Result(property = "productPrice",column = "productPrice",jdbcType = JdbcType.DOUBLE),
            @Result(property = "productDesc",column = "productDesc"/*,javaType = String.class*/,jdbcType = JdbcType.VARCHAR),
            @Result(property = "productStatus",column = "productStatus",jdbcType = JdbcType.INTEGER)
    })
    Product findProductById(Integer productId);

    @Select(" select * from product where id=#{productId}")
    Product getProductById(Integer productId);

    @Update(" update product set productNum=#{productNum},productName=#{productName},cityName=#{cityName},DepartureTime=#{departureTime},productPrice=#{productPrice},productDesc=#{productDesc},productStatus=#{productStatus} where id=#{id}")
    void updateProduct(Product product);
}
